// pages/user-my-follow/user-my-follow.js
var app = getApp()
Page({
  data: {
    currentTab: 0,
    pageNum: 1, //页数
    pageSize: 10, //每页数量
    follow: "", //关注数据
    imgUrl: app.globalData.imgUrl,
    localImg: app.globalData.staticimgUrl,  // 本地图片
  },
  
  onLoad: function (options) {
    this.follow(); //关注列表
    this.fans();
  },
  //关注列表
  follow: function () {
    var that = this;
    var userid = wx.getStorageSync('userid');
    app.request({
      url: 'doctor/followApi/getFollowList',
      data: {
        userId: userid, //用户id
        pageNum: that.data.pageNum, //页数
        pageSize: that.data.pageSize, //每页数量
      },
      success(res) {
        that.setData({
          follow: res.data
        })
      }
    })
  },
  //粉丝列表
  fans: function () {
    var that = this;
    var userid = wx.getStorageSync('userid');
    app.request({
      url: 'doctor/followApi/getFansList',
      data: {
        userId: userid, //用户id
        pageNum: that.data.pageNum, //页数
        pageSize: that.data.pageSize, //每页数量
      },
      success(res) {
        that.setData({
          fans: res.data
        })
      }
    })
  },

  //删除关注
  delfollow: function (e) {
    var that = this;
    var followId = e.currentTarget.dataset.id;
    wx.showModal({
      title: '提示',
      content: '确定要取消关注么？',
      success(res) {
        if (res.confirm) {
          
          app.request({
            url: 'doctor/followApi/deleteFollow',
            data: {
              followId
            },
            success(res) {
              that.follow(); //关注列表
            }
          })


        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
    
  },

  //滑动切换
  swiperTab: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  //点击切换
  clickTab: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
    var type = e.target.dataset.current;
    if (type == 0) {
      that.follow(); //关注列表
    } else {
      that.fans(); //粉丝列表
    }
  },

})